﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.Collections;

namespace PMSSys
{
    public class followupController
    {
        private DBconnentor dbConnect;
        public DBconnentor DbConnect
        {
            set { dbConnect = value; }
        }

        public bool add(FUE fue)
        {
            MySqlCommand query = new MySqlCommand(@"INSERT INTO followup(p_id, follow_date, blood_hgbhct, blood_wbc, blood_bseg_lympho, blood_blast, blood_platelets, blood_anc, blood_eos_mono,
            probfever, probbleeding, probpain, probapetite, probothers, pp_temp, pp_hr_bp, ppadenophaty, ppabdomen, ppskin, pprectal,
            ppsensory, ppweight, ppheent, ppchest_lungs, ppliver, ppextremities, ppneuro, ppheight, ppmucosa, ppheart, ppspleen,
            ppgenitalla,  ppmotor,  ppdtr,  chemonotes,  intrathetcaltransfusion,  intrathetcalprbc, intrathetcalplatelet, intrathetcalffp, intrathetcalbma,
            intrathetcalcryo, intrathetcalcorebiop, intrathetcalothers, next_followup)
            VALUES(@P_ID, @FOLLOW_DATE, @BLOOD_HGBHCT, @BLOOD_WBC, @BLOOD_BSEG_LYMPHO, @BLOOD_BLAST, @BLOOD_PLATELETS, @BLOOD_ANC, @BLOOD_EOS_MONO,
            @PROBFEVER, @PROBBLEEDING, @PROBPAIN, @PROBAPETITE, @PROBOTHERS, @PP_TEMP, @PP_HR_BP, @PPADENOPHATY, @PPABDOMEN, @PPSKIN, @PPRECTAL,
            @PPSENSORY,  @PPWEIGHT, @PPHEENT, @PPCHEST_LUNGS, @PPLIVER, @PPEXTREMITIES, @PPNEURO, @PPHEIGHT,  @PPMUCOSA,  @PPHEART,  @PPSPLEEN,
            @PPGENITALLA, @PPMOTOR, @PPDTR, @CHEMONOTES, @INTRATHETCALTRANSFUSION, @INTRATHETCALPRBC, @INTRATHETCALPLATELET,  
            @INTRATHETCALFFP,  @INTRATHETCALBMA, @INTRATHETCALCRYO, @INTRATHETCALCOREBIOP, @INTRATHETCALOTHERS, @NEXT_FOLLOWUP)", dbConnect.getConnection());

            query.Parameters.Add(new MySqlParameter("@P_ID", MySqlDbType.Int32)).Value = fue.PatientID;
            query.Parameters.Add(new MySqlParameter("@FOLLOW_DATE", MySqlDbType.DateTime)).Value = fue.FueDate;
            query.Parameters.Add(new MySqlParameter("@BLOOD_HGBHCT", MySqlDbType.String)).Value = fue.Blood_hgbhct;
            query.Parameters.Add(new MySqlParameter("@BLOOD_WBC", MySqlDbType.String)).Value = fue.Blood_wbc;
            query.Parameters.Add(new MySqlParameter("@BLOOD_BSEG_LYMPHO", MySqlDbType.String)).Value = fue.Blood_bseg_lympho;
            query.Parameters.Add(new MySqlParameter("@BLOOD_BLAST", MySqlDbType.String)).Value = fue.Blood_blast;
            query.Parameters.Add(new MySqlParameter("@BLOOD_PLATELETS", MySqlDbType.String)).Value = fue.Blood_platelets;
            query.Parameters.Add(new MySqlParameter("@BLOOD_ANC", MySqlDbType.String)).Value = fue.Blood_anc;
            query.Parameters.Add(new MySqlParameter("@BLOOD_EOS_MONO", MySqlDbType.String)).Value = fue.Blood_eos_mono;
            query.Parameters.Add(new MySqlParameter("@PROBFEVER", MySqlDbType.String)).Value = fue.Probfever;
            query.Parameters.Add(new MySqlParameter("@PROBBLEEDING", MySqlDbType.String)).Value = fue.Probbleeding;
            query.Parameters.Add(new MySqlParameter("@PROBPAIN", MySqlDbType.String)).Value = fue.Probpain;
            query.Parameters.Add(new MySqlParameter("@PROBAPETITE", MySqlDbType.String)).Value = fue.Probapetite;
            query.Parameters.Add(new MySqlParameter("@PROBOTHERS", MySqlDbType.String)).Value = fue.Probothers;
            query.Parameters.Add(new MySqlParameter("@PP_TEMP", MySqlDbType.String)).Value = fue.Ppe_temp;
            query.Parameters.Add(new MySqlParameter("@PP_HR_BP", MySqlDbType.String)).Value = fue.Ppe_hr_bp;
            query.Parameters.Add(new MySqlParameter("@PPADENOPHATY", MySqlDbType.String)).Value = fue.Ppadenophaty;
            query.Parameters.Add(new MySqlParameter("@PPABDOMEN", MySqlDbType.String)).Value = fue.Ppabdomen;
            query.Parameters.Add(new MySqlParameter("@PPSKIN", MySqlDbType.String)).Value = fue.Ppskin;
            query.Parameters.Add(new MySqlParameter("@PPRECTAL", MySqlDbType.String)).Value = fue.Pprectal;
            query.Parameters.Add(new MySqlParameter("@PPSENSORY", MySqlDbType.String)).Value = fue.Ppsensory;
            query.Parameters.Add(new MySqlParameter("@PPWEIGHT", MySqlDbType.String)).Value = fue.Ppweight;
            query.Parameters.Add(new MySqlParameter("@PPHEENT", MySqlDbType.String)).Value = fue.Ppheent;
            query.Parameters.Add(new MySqlParameter("@PPCHEST_LUNGS", MySqlDbType.String)).Value = fue.Ppchest;
            query.Parameters.Add(new MySqlParameter("@PPLIVER", MySqlDbType.String)).Value = fue.Ppliver;
            query.Parameters.Add(new MySqlParameter("@PPEXTREMITIES", MySqlDbType.String)).Value = fue.Ppextremities;
            query.Parameters.Add(new MySqlParameter("@PPNEURO", MySqlDbType.String)).Value = fue.Ppneuro;
            query.Parameters.Add(new MySqlParameter("@PPHEIGHT", MySqlDbType.String)).Value = fue.Ppheight;
            query.Parameters.Add(new MySqlParameter("@PPMUCOSA", MySqlDbType.String)).Value = fue.Ppmucosa;
            query.Parameters.Add(new MySqlParameter("@PPHEART", MySqlDbType.String)).Value = fue.Ppheart;
            query.Parameters.Add(new MySqlParameter("@PPSPLEEN", MySqlDbType.String)).Value = fue.Ppspleen;
            query.Parameters.Add(new MySqlParameter("@PPGENITALLA", MySqlDbType.String)).Value = fue.Ppgenitalla;
            query.Parameters.Add(new MySqlParameter("@PPMOTOR", MySqlDbType.String)).Value = fue.Ppmotor;
            query.Parameters.Add(new MySqlParameter("@PPDTR", MySqlDbType.String)).Value = fue.Ppdtr;
            query.Parameters.Add(new MySqlParameter("@CHEMONOTES", MySqlDbType.String)).Value = fue.Chemonotes;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALTRANSFUSION", MySqlDbType.String)).Value = fue.Intrathetcaltransfusion;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALPRBC", MySqlDbType.String)).Value = fue.Intrathetcalprbc;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALPLATELET", MySqlDbType.String)).Value = fue.Intrathetcalplatelet;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALFFP", MySqlDbType.String)).Value = fue.Intrathetcalffp;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALBMA", MySqlDbType.String)).Value = fue.Intrathetcalbma;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALCRYO", MySqlDbType.String)).Value = fue.Intrathetcalcryo;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALCOREBIOP", MySqlDbType.String)).Value = fue.Intrathetcalcorebiop;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALOTHERS", MySqlDbType.String)).Value = fue.Intrathetcalothers;
            query.Parameters.Add(new MySqlParameter("@NEXT_FOLLOWUP", MySqlDbType.DateTime)).Value = fue.NextFueDate;

            return dbConnect.nonQueryExecute(query);     
        }
        public DataTable getDataTable(int p_id)
        {
            string str = "SELECT fue_id, follow_date AS `Date Issued`, next_followup AS `Next Follow-Up Date` FROM followup WHERE p_id = " + p_id.ToString();
            return dbConnect.view(str);
        }
        public bool update(FUE fue)
        {
            MySqlCommand query = new MySqlCommand(@"UPDATE followup SET follow_date = @FOLLOW_DATE,  blood_hgbhct = @BLOOD_HGBHCT,  blood_wbc = @BLOOD_WBC,  
            blood_bseg_lympho = @BLOOD_BSEG_LYMPHO,  blood_blast = @BLOOD_BLAST, blood_platelets = @BLOOD_PLATELETS,  blood_anc = @BLOOD_ANC,  blood_eos_mono = @BLOOD_EOS_MONO,
            probfever = @PROBFEVER,  probbleeding = @PROBBLEEDING,  probpain = @PROBPAIN, probapetite = @PROBAPETITE, probothers = @PROBOTHERS, pp_temp = @PP_TEMP, 
            pp_hr_bp = @PP_HR_BP, ppadenophaty = @PPADENOPHATY,  ppabdomen = @PPABDOMEN,  ppskin = @PPSKIN,  pprectal = @PPRECTAL, 
            ppsensory = @PPSENSORY,  ppweight = @PPWEIGHT, ppheent = @PPHEENT, ppchest_lungs = @PPCHEST_LUNGS,  ppliver = @PPLIVER,  ppextremities = @PPEXTREMITIES, 
            ppneuro = @PPNEURO,  ppheight = @PPHEIGHT, ppmucosa = @PPMUCOSA,  ppheart = @PPHEART,  ppspleen = @PPSPLEEN, ppgenitalla = @PPGENITALLA,  
            ppmotor = @PPMOTOR,  ppdtr = @PPDTR, chemonotes = @CHEMONOTES, intrathetcaltransfusion = @INTRATHETCALTRANSFUSION, intrathetcalprbc = @INTRATHETCALPRBC,  
            intrathetcalplatelet = @INTRATHETCALPLATELET,  intrathetcalffp = @INTRATHETCALFFP,  intrathetcalbma = @INTRATHETCALBMA,
            intrathetcalcryo = @INTRATHETCALCRYO,  intrathetcalcorebiop = @INTRATHETCALCOREBIOP,  intrathetcalothers = @INTRATHETCALOTHERS, next_followup = @NEXT_FOLLOWUP WHERE p_id = @P_ID AND fue_id = @FUE_ID", dbConnect.getConnection());

            query.Parameters.Add(new MySqlParameter("@P_ID", MySqlDbType.Int32)).Value = fue.PatientID;
            query.Parameters.Add(new MySqlParameter("@FUE_ID", MySqlDbType.Int32)).Value = fue.FueID;
            query.Parameters.Add(new MySqlParameter("@FOLLOW_DATE", MySqlDbType.DateTime)).Value = fue.FueDate;
            query.Parameters.Add(new MySqlParameter("@BLOOD_HGBHCT", MySqlDbType.String)).Value = fue.Blood_hgbhct;
            query.Parameters.Add(new MySqlParameter("@BLOOD_WBC", MySqlDbType.String)).Value = fue.Blood_wbc;
            query.Parameters.Add(new MySqlParameter("@BLOOD_BSEG_LYMPHO", MySqlDbType.String)).Value = fue.Blood_bseg_lympho;
            query.Parameters.Add(new MySqlParameter("@BLOOD_BLAST", MySqlDbType.String)).Value = fue.Blood_blast;
            query.Parameters.Add(new MySqlParameter("@BLOOD_PLATELETS", MySqlDbType.String)).Value = fue.Blood_platelets;
            query.Parameters.Add(new MySqlParameter("@BLOOD_ANC", MySqlDbType.String)).Value = fue.Blood_anc;
            query.Parameters.Add(new MySqlParameter("@BLOOD_EOS_MONO", MySqlDbType.String)).Value = fue.Blood_eos_mono;
            query.Parameters.Add(new MySqlParameter("@PROBFEVER", MySqlDbType.String)).Value = fue.Probfever;
            query.Parameters.Add(new MySqlParameter("@PROBBLEEDING", MySqlDbType.String)).Value = fue.Probbleeding;
            query.Parameters.Add(new MySqlParameter("@PROBPAIN", MySqlDbType.String)).Value = fue.Probpain;
            query.Parameters.Add(new MySqlParameter("@PROBAPETITE", MySqlDbType.String)).Value = fue.Probapetite;
            query.Parameters.Add(new MySqlParameter("@PROBOTHERS", MySqlDbType.String)).Value = fue.Probothers;
            query.Parameters.Add(new MySqlParameter("@PP_TEMP", MySqlDbType.String)).Value = fue.Ppe_temp;
            query.Parameters.Add(new MySqlParameter("@PP_HR_BP", MySqlDbType.String)).Value = fue.Ppe_hr_bp;
            query.Parameters.Add(new MySqlParameter("@PPADENOPHATY", MySqlDbType.String)).Value = fue.Ppadenophaty;
            query.Parameters.Add(new MySqlParameter("@PPABDOMEN", MySqlDbType.String)).Value = fue.Ppabdomen;
            query.Parameters.Add(new MySqlParameter("@PPSKIN", MySqlDbType.String)).Value = fue.Ppskin;
            query.Parameters.Add(new MySqlParameter("@PPRECTAL", MySqlDbType.String)).Value = fue.Pprectal;
            query.Parameters.Add(new MySqlParameter("@PPSENSORY", MySqlDbType.String)).Value = fue.Ppsensory;
            query.Parameters.Add(new MySqlParameter("@PPWEIGHT", MySqlDbType.String)).Value = fue.Ppweight;
            query.Parameters.Add(new MySqlParameter("@PPHEENT", MySqlDbType.String)).Value = fue.Ppheent;
            query.Parameters.Add(new MySqlParameter("@PPCHEST_LUNGS", MySqlDbType.String)).Value = fue.Ppchest;
            query.Parameters.Add(new MySqlParameter("@PPLIVER", MySqlDbType.String)).Value = fue.Ppliver;
            query.Parameters.Add(new MySqlParameter("@PPEXTREMITIES", MySqlDbType.String)).Value = fue.Ppextremities;
            query.Parameters.Add(new MySqlParameter("@PPNEURO", MySqlDbType.String)).Value = fue.Ppneuro;
            query.Parameters.Add(new MySqlParameter("@PPHEIGHT", MySqlDbType.String)).Value = fue.Ppheight;
            query.Parameters.Add(new MySqlParameter("@PPMUCOSA", MySqlDbType.String)).Value = fue.Ppmucosa;
            query.Parameters.Add(new MySqlParameter("@PPHEART", MySqlDbType.String)).Value = fue.Ppheart;
            query.Parameters.Add(new MySqlParameter("@PPSPLEEN", MySqlDbType.String)).Value = fue.Ppspleen;
            query.Parameters.Add(new MySqlParameter("@PPGENITALLA", MySqlDbType.String)).Value = fue.Ppgenitalla;
            query.Parameters.Add(new MySqlParameter("@PPMOTOR", MySqlDbType.String)).Value = fue.Ppmotor;
            query.Parameters.Add(new MySqlParameter("@PPDTR", MySqlDbType.String)).Value = fue.Ppdtr;
            query.Parameters.Add(new MySqlParameter("@CHEMONOTES", MySqlDbType.String)).Value = fue.Chemonotes;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALTRANSFUSION", MySqlDbType.String)).Value = fue.Intrathetcaltransfusion;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALPRBC", MySqlDbType.String)).Value = fue.Intrathetcalprbc;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALPLATELET", MySqlDbType.String)).Value = fue.Intrathetcalplatelet;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALFFP", MySqlDbType.String)).Value = fue.Intrathetcalffp;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALBMA", MySqlDbType.String)).Value = fue.Intrathetcalbma;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALCRYO", MySqlDbType.String)).Value = fue.Intrathetcalcryo;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALCOREBIOP", MySqlDbType.String)).Value = fue.Intrathetcalcorebiop;
            query.Parameters.Add(new MySqlParameter("@INTRATHETCALOTHERS", MySqlDbType.String)).Value = fue.Intrathetcalothers;
            query.Parameters.Add(new MySqlParameter("@NEXT_FOLLOWUP", MySqlDbType.DateTime)).Value = fue.NextFueDate;

            return dbConnect.nonQueryExecute(query);
        }
        public FUE objectFiller(FUE fueObject)
        {
            string str = "SELECT * FROM followup where fue_id = " + fueObject.FueID.ToString();
            DataTable temp = dbConnect.view(str);
            IEnumerator iter = temp.Rows[0].ItemArray.GetEnumerator();
            iter.MoveNext();
            iter.MoveNext();
            
            fueObject.PatientID = (int)iter.Current;
            iter.MoveNext();

            fueObject.FueDate = (DateTime)iter.Current;
            iter.MoveNext();

            fueObject.Blood_hgbhct = (string)iter.Current;
            iter.MoveNext();

            fueObject.Blood_wbc = (string)iter.Current;
            iter.MoveNext();

            fueObject.Blood_bseg_lympho = (string)iter.Current;
            iter.MoveNext();

            fueObject.Blood_blast = (string)iter.Current;
            iter.MoveNext();

            fueObject.Blood_platelets = (string)iter.Current;
            iter.MoveNext();

            fueObject.Blood_anc = (string)iter.Current;
            iter.MoveNext();

            fueObject.Blood_eos_mono = (string)iter.Current;
            iter.MoveNext();

            fueObject.Probfever = (string)iter.Current;
            iter.MoveNext();

            fueObject.Probapetite = (string)iter.Current;
            iter.MoveNext();

            fueObject.Probbleeding = (string)iter.Current;
            iter.MoveNext();

            fueObject.Probpain = (string)iter.Current;
            iter.MoveNext();

            fueObject.Probothers = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppe_temp = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppe_hr_bp = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppadenophaty = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppabdomen = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppskin = (string)iter.Current;
            iter.MoveNext();

            fueObject.Pprectal = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppsensory = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppweight = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppheent = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppchest = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppliver = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppextremities = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppneuro = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppheight = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppmucosa = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppheart = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppspleen = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppgenitalla = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppmotor = (string)iter.Current;
            iter.MoveNext();

            fueObject.Ppdtr = (string)iter.Current;
            iter.MoveNext();

            fueObject.Chemonotes = (string)iter.Current;
            iter.MoveNext();
            
            fueObject.Intrathetcaltransfusion = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalprbc = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalplatelet = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalffp = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalbma = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalcryo = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalcorebiop = (string)iter.Current;
            iter.MoveNext();

            fueObject.Intrathetcalothers = (string)iter.Current;
            iter.MoveNext();

            fueObject.NextFueDate = (DateTime)iter.Current;
            iter.MoveNext();

            return fueObject;
        }
        public bool delete(string fueID)
        {
            string str = "DELETE FROM followup WHERE fue_id =" + fueID;
            return dbConnect.delete(str);
        }
    }
}
